package com.dk.service.impl;

import com.dk.mapper.CooperativeMerchantMapper;
import com.dk.pojo.CooperativeMerchant;
import com.dk.service.CooperativeMerchantService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dk.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 帅杰
 * @since 2021-08-13
 */
@Service
public class CooperativeMerchantServiceImpl extends ServiceImpl<CooperativeMerchantMapper, CooperativeMerchant> implements CooperativeMerchantService {

    @Autowired
    private CooperativeMerchantMapper cooperativeMerchantMapper;

    @Override
    public List<CooperativeMerchant> toSelect() {
        return cooperativeMerchantMapper.selectList(null);
    }

    @Override
    public void toInsert(CooperativeMerchant merchant) {
        //定义一个密码
        String str = "1234";
        String salt = ShiroUtils.generateSalt(6);
        String md5 = ShiroUtils.encryptPassword("MD5", str ,salt, 5);
        merchant.setPassword(md5);
        merchant.setSalt(salt);
      cooperativeMerchantMapper.insert(merchant);
    }

    @Override
    public void toUpdate(CooperativeMerchant merchant) {
        cooperativeMerchantMapper.updateById(merchant);
    }

    @Override
    public void toDetele(Long merchantId) {
        cooperativeMerchantMapper.deleteById(merchantId);
    }


}
